﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Best.SmartCms.CodeGeneration.Model
{
    /// <summary>
    /// 列的类型
    /// </summary>
    public enum ColumnType
    {
        [Description("Guid")]
        Guid,
        [Description("int")]
        Int,
        [Description("long")]
        Long,
        [Description("string")]
        String,
        [Description("DateTime")]
        DateTime,
        [Description("bool")]
        Bool,
        [Description("float")]
        Float,
        [Description("double")]
        Double,
        [Description("decimal")]
        Decimal


    }

    public enum InputType
    {
        Input,
        CheckBox,
        RadioBox,
        Textarea,
        ComboBox
    }

    public static class EnumHelper
    {
        public static string GetEnumDescription(Enum value)
        {
            var enumType = value.GetType();
            var name = Enum.GetName(enumType, value);
            if (name == null) return null;
            var fieldInfo = enumType.GetField(name);
            if (fieldInfo == null) return null;
            if (Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute), false) is DescriptionAttribute
                attr)
            {
                return attr.Description;
            }

            return null;
        }


        public static string ToFirstCharLower(this string word)
        {
            if (string.IsNullOrEmpty(word)) { return ""; }
            string initialLetter = word.Substring(0, 1).ToLower();
            if (word.Length == 1) { return initialLetter; }
            string otherLetters = word.Substring(1, word.Length - 1);
            string ret = initialLetter + otherLetters;
            return ret;
        }

        public static string ToJsColumnType(this ColumnType columnType)
        {
            switch (columnType)
            {
                case ColumnType.Bool:
                    return "boolean";
                case ColumnType.Int:
                case ColumnType.Double:
                case ColumnType.Long:
                case ColumnType.Float:
                case ColumnType.Decimal:
                    return "number";
                case ColumnType.String:
                case ColumnType.Guid:
                case ColumnType.DateTime:
                    return "string";
            }

            return "string";
        }
    }
}
